import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:thinking/config/_.dart';
import 'package:thinking/utils/_.dart';
import 'package:thinking/views/Index/PersonalPop.dart';
import 'package:thinking/views/Personal/Personal.dart';

import 'Dynamic/Dynamic.dart';
import 'Index/Index.dart';

///首页
class App extends StatefulWidget{

  @override
  _App createState() =>_App();
}

class _App extends State<App> with SingleTickerProviderStateMixin,AutomaticKeepAliveClientMixin{
  
  late TabController _tabController;

  @override
  bool get wantKeepAlive => true;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
    CheckUpdate().check(context);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  Widget bottom(){
    return Container(
      height: Screen.setHeight(50),
      decoration: BoxDecoration(
        color: ColorConfig.WhiteObsBackColor,
        border: Border(top: BorderSide(color: ColorConfig.LineColor)),
      ),
      child: TabBar(
        indicatorColor:Colors.transparent,
        labelColor: ColorConfig.ThemeColor,
        unselectedLabelColor: ColorConfig.TextColor,
        controller: _tabController,
        indicatorWeight: 0.1 ,
        labelStyle: TextStyle(height: 0.5),
        tabs: <Tab>[
          Tab(text: "首页", icon:  Icon(Icons.home)),
          Tab(text: "动态", icon:  Icon(Icons.message)),
          Tab(text: "我的", icon:  Icon(Icons.person)),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    Core.setStatusThemeColor(color:Colors.transparent,textColor: 'Light',isBarColor: true);
    Config.context = context;
    return Scaffold(
      body: TabBarView(
        controller: _tabController,
        children: [
          Builder(
            builder:(BuildContext context){
              return  Index(clickHead: ()=>{Scaffold.of(context).openDrawer()});
            }),
          Dynamic(),
          Personal(userId: SPreferences().getInt('user_Id'),)
        ],
      ),
      bottomNavigationBar: bottom(),
      drawer: PersonalPop(),
      drawerEdgeDragWidth: 0.0,
    );
  }
}